﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using System.Collections.Generic;
using OA.DBUtility;
using OA.Model;

namespace OA.Manager
{
    /// <summary>
    /// 数据访问类:Project
    /// </summary>
    public partial class ProjectManager
    {
        private SqlService<ProjectInfo> _sqlService = null;

        public ProjectManager()
        {
            _sqlService = new SqlService<ProjectInfo>();
        }

        #region  Method

        /// <summary>
        /// 插入新记录
        /// </summary>
        /// <param name="projectInfo"></param>
        /// <returns></returns>
        public bool InsertProjectInfo(ProjectInfo projectInfo)
        {
            return _sqlService.SaveEntity(projectInfo);
        }

        /// <summary>
        /// 根据打印任务ID获得打印任务信息
        /// </summary>
        /// <param name="taskID"></param>
        /// <returns></returns>
        public ProjectInfo GetProjectInfoByID(int ID)
        {
            Dictionary<string, object> dic = new Dictionary<string, object>();
            dic.Add("ID", ID);
            return _sqlService.GetSingleByFields(dic, null);
        }

        public DataTable GetPaged(int pageIndex, int pageSize, ref int total)
        {
            return _sqlService.GetPaged("*", "", pageIndex, pageSize, ref pageSize, ref total);
        }

        public DataTable GetSearchPaged(ProjectInfo info, int pageIndex, int pageSize, ref int total)
        {
            return _sqlService.GetSearchPaged(info, pageIndex, pageSize, ref total);
        }

        /// <summary>
        /// 判断该打印任务是否存在
        /// </summary>
        /// <param name="projectInfo"></param>
        /// <returns></returns>
        public bool IsExistProjectInfo(ProjectInfo projectInfo)
        {
            return _sqlService.IsExist(projectInfo);
        }

        /// <summary>
        /// 根据指定的字段更新，字段名是数据库中对应的名称
        /// </summary>
        /// <param name="projectInfo"></param>
        /// <param name="needUpdateFields"></param>
        /// <returns></returns>
        public bool UpdateProjectInfo(ProjectInfo projectInfo, List<string> needUpdateFields)
        {
            return _sqlService.UpdateByFields(projectInfo, needUpdateFields);
        }

        /// <summary>
        /// 删除该检查任务
        /// </summary>
        /// <param name="projectInfo"></param>
        /// <returns></returns>
        public bool DeleteProjectInfo(ProjectInfo projectInfo)
        {
            return _sqlService.DeleteEntity(projectInfo);
        }

        #endregion  Method
    }
}

